// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { NativeEventEmitter, DeviceEventEmitter, TextInput, NativeModules, Platform, StyleSheet, Text, View, TouchableHighlight, Alert, InteractionManager } from 'react-native';
import { ToastExample, BodyPlusModule } from '../../util/nativeModules';

// 引入第三方依赖
import _ from 'lodash';
import axios from 'axios';
import Icon from 'react-native-vector-icons/dist/Ionicons';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';

// antd 按需加载
import { Tabs, Toast } from '@ant-design/react-native';

// 引入 处理数据 所需文件
// import { getStoreClass, getHotStore, getUserTkQyk, getStoreList_jiaofei, getAdsList } from './module/module.js'

// 引入样式
import Style from './style/style.js';

// 引入公用组件
import { Status, VipCard, Title, NetInfoScene, Results, RefreshScrollView } from '../../components/index.js'

// 引入专用组件
import { } from './components/index.js'

// 引入工具包

import { nblogo, classDefault } from '../../util/images.js'
import { press, size, longitude, latitude, ScreenWidth, defaultDataList, onEndReached, onRefresh, concatDataList, defaultPage } from '../../util/utils.js'



class Home extends Component {

  constructor(props) {
    super(props)
    this.state = {
      deviceList: []
    }

  }


  componentDidMount() {
    // DeviceEventEmitter.addListener('deviceList', (e) => {
    //   console.log(e)
    //   this.setState({
    //     deviceList: JSON.parse(e.eventProperty)
    //   })
    //   // console.log('componentDidMount')
    //   // alert("Android send js msg success");
    // });
  }

  componentWillMount() {
    // DeviceEventEmitter.addListener('deviceList', function (e) {
    //   console.log(e)
    //   // console.log('componentWillMount')
    //   // alert("Android send js msg success");
    // });
  }

  search() {
    BodyPlusModule.Search()
  }
  connectDevice(device) {
    console.log(device)
    BodyPlusModule.connectDevice(device.macAddress, device.deviceSn, device.rssi, device.deviceName, device.isDfuStatus)
  }
  startHRV() {
    BodyPlusModule.startHRV()
  }

  reName() {
    BodyPlusModule.reName('xyy')
  }



  render() {
    const { deviceList } = this.state
    return (
      <View style={[Style.container]}>
        <Status />
        <View style={{
          paddingLeft: 15,
          flexDirection: 'row',
          alignItems: 'center',
          justifyContent: 'space-between',
        }}>
          <Text onPress={() => ToastExample.show('弹出Toast', ToastExample.SHORT)}>弹出Toast</Text>
          <TextInput placeholder='修改名称'
            onChange={(e) => {
              console.log(e)
              this.name
            }}></TextInput>
          <TouchableHighlight
            onPress={() => this.reName()}
            style={{
              padding: 20
            }}
          >
            <Text>修改名称</Text>
          </TouchableHighlight>
          <TouchableHighlight
            onPress={() => this.search()}
            style={{
              padding: 20
            }}
          >
            <Text>搜索设备</Text>
          </TouchableHighlight>
          <TouchableHighlight
            onPress={() => this.startHRV()}
            style={{
              padding: 20
            }}
          >
            <Text>开启波形</Text>
          </TouchableHighlight>
          {/* <TouchableHighlight
          onPress={() => this.showDeviceLists()}
        >
          <Text>显示设备列表</Text>
        </TouchableHighlight> */}
          {deviceList.map((item, index) => {
            return (
              <TouchableHighlight onPress={() => {
                this.connectDevice(item)
              }} style={{}} key={index}>
                <View style={{}}>
                  <View style={{}}>
                    <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{item.macAddress}</Text>
                  </View>
                  <View style={{}}>
                    <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{item.deviceSn}</Text>
                  </View>
                  <View style={{}}>
                    <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{item.rssi}</Text>
                  </View>
                  <View style={{}}>
                    <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{item.deviceName}</Text>
                  </View>
                  <View style={{}}>
                    <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{item.isDfuStatus}</Text>
                  </View>
                </View>
              </TouchableHighlight>
            )
          })
          }
        </View>

      </View >
    );
  }
}



export default connect(({ user, storeClass, hotStore, tkList, storeListJiaoFei, adsList }) => ({
  user,
  storeClass,
  hotStore,
  tkList,
  storeListJiaoFei,
  adsList
}))(pureRender(Home))
